using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Terra.Data.Entities.Identity;
using Terra.Data.Models.Identity;

namespace Terra.Data.Repository.Identity;

/// <summary>
/// 菜单仓储接口
/// </summary>
public interface IMenuRepository : IRepository<Menu, Guid>
{
    /// <summary>
    /// 根据菜单名称查找菜单
    /// </summary>
    /// <param name="name">菜单名称</param>
    /// <returns>菜单实体</returns>
    Task<Menu> FindByNameAsync(string name);

    /// <summary>
    /// 获取全部菜单，按照排序号排序
    /// </summary>
    /// <returns>所有菜单</returns>
    Task<List<Menu>> GetAllMenusAsync();

    /// <summary>
    /// 根据路径查找菜单
    /// </summary>
    /// <param name="path">路由路径</param>
    /// <returns>菜单实体</returns>
    Task<Menu> FindByPathAsync(string path);

    /// <summary>
    /// 获取子菜单列表
    /// </summary>
    /// <param name="parentId">父菜单ID</param>
    /// <returns>子菜单列表</returns>
    Task<List<Menu>> GetChildrenAsync(Guid parentId);

    /// <summary>
    /// 获取菜单分页列表
    /// </summary>
    /// <param name="query">查询条件</param>
    /// <returns>菜单列表和总数</returns>
    Task<(List<Menu> Items, int TotalCount)> GetPagedMenusAsync(MenuQueryDto query);

    /// <summary>
    /// 检查菜单名称是否已存在
    /// </summary>
    /// <param name="name">菜单名称</param>
    /// <param name="excludeMenuId">排除的菜单ID</param>
    /// <returns>是否存在</returns>
    Task<bool> ExistsByNameAsync(string name, Guid? excludeMenuId = null);

    /// <summary>
    /// 检查菜单路径是否已存在
    /// </summary>
    /// <param name="path">菜单路径</param>
    /// <param name="excludeMenuId">排除的菜单ID</param>
    /// <returns>是否存在</returns>
    Task<bool> ExistsByPathAsync(string path, Guid? excludeMenuId = null);

    /// <summary>
    /// 批量删除菜单
    /// </summary>
    /// <param name="menuIds">菜单ID列表</param>
    /// <returns>删除结果和失败ID列表</returns>
    Task<(bool Succeeded, List<Guid> FailedIds)> DeleteMenusAsync(IEnumerable<Guid> menuIds);
}